package com.gugee.ins.data.collector.bloggerfollower.listener;

import com.gugee.ins.data.collector.bloggerfollower.config.InsBloggerFollowerConfig;
import com.gugee.ins.data.collector.bloggerfollower.service.InsBloggerFollowerService;
import com.gugee.ins.data.common.consumer.AbstractGugeeConsumerHandler;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * InsBloggerFollowerListener
 *
 * @author Huangxin
 */
@Component
@Slf4j
public class InsBloggerFollowerListener {

    /**
     * insBloggerFollowerConfig
     */
    @Autowired
    private InsBloggerFollowerConfig insBloggerFollowerConfig;

    /**
     * InsCommentService
     */
    @Autowired
    private InsBloggerFollowerService insBloggerFollowerService;

    private InsBloggerFollowerHandler collectHandler = new InsBloggerFollowerHandler();

    /**
     * 监听任务,完成评论采集
     * @param messages
     * @param ack
     */
    @KafkaListener(id="${kafka.consumer.group.insBloggerFollower.id}",
            topics = {"${kafka.topics.insBloggerFollower.online}","${kafka.topics.insBloggerFollower.priority}"},
            containerFactory = "factoryInsBloggerFollowingAck")
    public void bloggerMainCollect(List<InsBloggerMessage> messages, Acknowledgment ack) {
        collectHandler.handle("InsBloggerFollower",messages,insBloggerFollowerConfig.getAcceptInsBloggerFollowerMsgTimeMinRange(),ack);
    }

    class InsBloggerFollowerHandler extends AbstractGugeeConsumerHandler<InsBloggerMessage>{
        @Override
        public void dealMsg(List<InsBloggerMessage> messages) {
            insBloggerFollowerService.handleInsBloggerFollower(messages);
        }
    }
}
